package com.work.stock.service;

import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.BusinessActionContextParameter;
import io.seata.rm.tcc.api.LocalTCC;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;

/**
 * @author 猿仁
 * @date 2023-03-11 15:00
 */
@LocalTCC
public interface StockService {


    /**
     * 减库存
     *
     * @param commodityCode
     * @param count
     */
    @TwoPhaseBusinessAction(name = "deduct", commitMethod = "busCommit", rollbackMethod = "busRollback", useTCCFence = true)
    void deduct(@BusinessActionContextParameter(paramName = "commodityCode") String commodityCode,
                @BusinessActionContextParameter(paramName = "count") int count);

    /**
     * 提交事务
     *
     * @param actionContext
     * @return
     */
    boolean busCommit(BusinessActionContext actionContext);

    /**
     * 回滚事务
     *
     * @param actionContext
     * @return
     */
    boolean busRollback(BusinessActionContext actionContext);
}
